from django.db import models
from mdeditor.fields import MDTextField
from django.contrib.auth.models import AbstractUser


# Create your models here.

class BaseModel(models.Model):
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_delete = models.BooleanField(default=False, verbose_name='是否删除')
    index = models.IntegerField(default=0, verbose_name="排序字段")

    class Meta:
        abstract = True


class Kind(BaseModel):
    name = models.CharField(verbose_name='菜系', max_length=10)

    class Meta:
        verbose_name = '菜系表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Menu(BaseModel):
    name = models.CharField(verbose_name='菜名', max_length=10)
    price = models.DecimalField(max_digits=11, decimal_places=2, verbose_name='价格')
    order_count = models.IntegerField(verbose_name='下单量')
    introduce = MDTextField(verbose_name='介绍')
    kinds = models.ForeignKey(to=Kind, on_delete=models.CASCADE)

    class Meta:
        verbose_name = '菜表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class ImageList(BaseModel):
    image = models.ImageField(upload_to='images/%Y/%M/%D', null=True, blank=True, verbose_name='菜图片')
    is_cover = models.BooleanField(default=False, verbose_name='是否封面')
    menus = models.ForeignKey(to=Menu, on_delete=models.CASCADE)

    class Meta:
        verbose_name = '图片表'
        verbose_name_plural = verbose_name


